﻿/*
 * Added by laoxu 2013-12-25 17:00:00
 * ---------------------------------------------------------------
 * for：added the DbContextFactory class,
 * It is get only one Database
 * ---------------------------------------------------------------
 * version:1.0
 * mail:lovexurongquan@163.com
 */



using System.Runtime.Remoting.Messaging;
using PetaPoco;

namespace HouodeIT.CloudePlatform.PL.Factory
{
    public class DbContextFactory
    {
        /// <summary>
        /// get Singleton instance for database.
        /// </summary>
        /// <param name="connectionStringName">connection string name in config</param>
        /// <returns>instance database</returns>
        public static Database GetCurrentContext(string connectionStringName)
        {
            var dbContext = CallContext.GetData("DbContextFactory") as Database;
            if (dbContext == null)
            {
                dbContext = new Database(connectionStringName);
                CallContext.SetData("DbContextFactory", dbContext);

            }
            return dbContext;
        } 
    }
}